home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr05
/
picbuttn.zip
/
README.TXT
< prev
Wrap
Text File
|
1993-07-03
|
4KB
|
65 lines
Here is a simple way to create the elegant "picture" buttons which grace
sophisticated programs... the buttons which have a picture or miniature
icon instead of a caption.
To test and view the demo program: copy the file PICBUTNS.FRM to your normal
VB workspace. Start VB, and from new project, select ADD FILE, with
PICBUTNS.FRM as the target. Remove the default FORM1.FRM from the project.
Your project should now consist of a blank GLOBAL.BAS and PICBUTNS.FRM.
Run the program. You will see a button with a pile of yellow poker chips,
which will click properly with the action of the mouse. How its done...
To generate this style of button in VB, at least in this simplistic mode,
requires three picture boxes. The first is the actual button which will
be visible to the user. This is the top button on PICBUTNS.FRM. On the
demo, this is picture1. The lower left picture box, picture2, is
the "up" picture, and picture3, the "down" picture. These latter
2 have their visible properties set to "0" or FALSE, so they are not seen
at run time. Clicking picture1 at run time generates two events
in sequence... the mousedown event and the mouseup event. At mousedown,
the code replaces picture1.picture with picture3.picture (the down picture)
At mouseup, the picture is again replaced, this time with picture2.picture,
the up picture. The code you wish to execute belongs after this swap. See
the comments in the code at the picture1_mouseup event.
The pictures are very easy to make. The two icon files represent the blank
up and down states of the button. Use iconworks to view them if you wish.
You don't need to make the buttons icon sized (you can manually bitmap them
instead with paintbrush) but it is much easier and convenient to do so.
Heres the easiest method, from the beginning, to make a picture button.
On a blank form, create three picture boxes. Set the autosize property to
TRUE for all three. Set the VISUAL property to false for the last two. Now
run iconworks alongside VB, and load the two icons, button1.ico and
button2.ico in two blank workspaces. In a third icon workspace, create the
picture you wish to appear on the button, but make it at least 4 pixels
smaller than a full icon, and leave the background white. Using the EDIT
tools on iconworks, COPY the picture you have drawn and PASTE it smack in
the middle of button1.ico (the up button). PASTE it again on button2.ico,
but move it, relative to the position you pasted it on button1.ico, exactly
2 pixels right and 1 pixel down. This generates the downward motion when
the user clicks your button. Remember when you COPY your picture to limit
the size of the copy to just your picture, and none of the blank
surrounding it. Otherwise, you will copy over the necessary greys of the
buttons and the shadowing will be lost.
You should now have two icons which represent the up and down button states
on iconworks. All the white and grey shadowing should be intact, and the
picture you drew will be displaced on the down icon 2 pixels right and 1
pixel down. Copy the ENTIRE up button icon and paste it into picture1
and picture2 on your VB form. Copy the entire down button icon and paste
this one into picture3. Save the icons if you wish.
Examine the code for the picture1_mousedown and picture1_mouseup events, and
it should be obvious how the coding works. The main drawback to this system
is the number of controls involved. I wouldn't care to create more than 3
or 4 picture buttons on a form in this manner, but just one is enough to
set your project apart from other VB programs.
My name is Kurt Bjorn, and I am a pilot for American Airlines, currently
living in Evanston. I would love to exchange ideas, especially for
VISUAL BASIC. This program amazes me with its elegance, power, and
simplicity. Drop me a message on the AQUILA BBS, in the WINDOWS
conference, J 6, especially if you have any questions on this technique
(or maybe you have a better way!) I'd like to hear from you.